package com.example.administrator.myapplication;

import android.graphics.Color;
import android.support.v4.view.PagerTabStrip;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private List<View> mViewList;
    private ViewPager mViewPager;
    private PagerTabStrip mTabStrip;
    private List<String> mTitle;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mViewList = new ArrayList<View>();
        View view1 = View.inflate(this,R.layout.view1,null);
        View view2 = View.inflate(this,R.layout.view2,null);
        View view3 = View.inflate(this,R.layout.view3,null);
        View view4 = View.inflate(this,R.layout.view4,null);
        mViewList.add(view1);
        mViewList.add(view2);
        mViewList.add(view3);
        mViewList.add(view4);
        //为ViewPager设置标题
        mTitle = new ArrayList<>();
        mTitle.add("第一页");
        mTitle.add("第二页");
        mTitle.add("第三页");
        mTitle.add("第四页");
        //为PagerTabStrip设置属性
        mTabStrip = (PagerTabStrip) findViewById(R.id.pager_tabstrip);
        mTabStrip.setTextColor(Color.GREEN);
        mTabStrip.setDrawFullUnderline(false);
        mTabStrip.setTabIndicatorColor(Color.BLUE);
        //初始化ViewPager
        mViewPager = (ViewPager) findViewById(R.id.view_pager);
        //创建ViewPager适配器
        MyPagerAdapter adapter = new MyPagerAdapter(mViewList,mTitle);

        mViewPager.setAdapter(adapter);


    }
}
